﻿using Max.PH4_2104A.Shopping.ThreeFrame.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH4_2104A.Shopping.ThreeFrame.DAL
{
    /// <summary>
    /// 系统用户的数据访问
    /// </summary>
    public class SystemUserDAL
    {
        MyDbContext _db;

        public SystemUserDAL(MyDbContext db)
        {
            _db = db;
        }

        /// <summary>
        /// 添加系统用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(SystemUserModel model)
        {
            _db.SystemUsers.Add(model);
            _db.SaveChanges();
            return 1;
        }

        /// <summary>
        /// 删除系统用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Delete(SystemUserModel model)
        {
            _db.SystemUsers.Remove(model);
            _db.SaveChanges();
            return 1;
        }

        /// <summary>
        /// 修改系统用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(SystemUserModel model)
        {
            _db.SystemUsers.Update(model);
            _db.SaveChanges();
            return 1;
        }

        /// <summary>
        /// 批量修改系统用户信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(List<SystemUserModel> model)
        {
            _db.SystemUsers.UpdateRange(model);
            _db.SaveChanges();
            return 1;
        }

        /// <summary>
        /// 获取所有信息
        /// </summary>
        /// <returns></returns>
        public IQueryable<SystemUserModel> GetAll()
        {
            return _db.SystemUsers;
        }
    }
}
